package day20171214;

import java.io.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class stringtest {
    public static void main(String[] args) {
        File file1=new File("G:\\所交作业");//所交的作业的信息
        File file2=new File("G:\\全班人员名单");//全班人信息
       FileOutputStream writer=null;
        try {
     writer=new FileOutputStream("G:\\未交作业人的名单.txt");
        } catch (IOException e) {
            e.printStackTrace();
        }

        File[] first=file1.listFiles();
File[] second=file2.listFiles();

        Map<String,String> map=new HashMap<>();
        List<String> list1=new ArrayList<>();
        List<String> list2=new ArrayList<>();


        int i=0;
for (File m:second){
    Matcher matcher= Pattern.compile("班(\\d+)+(\\D+)实(\\D+)")//一个括号代表省略的内容
            .matcher(m.getName());
    while(matcher.find()){//循环语句
        list2.add(matcher.group(1)+matcher.group(2));
        map.put(list2.get(i),list2.get(i));
    }
    i++;
}


        for (File n:first){
            // 增强循环
            Matcher matcher= Pattern.compile("班(\\d+)+(\\D+)实(\\D+)")//一个括号代表省略的内容
                    .matcher(n.getName());
            while(matcher.find()){//循环语句
                list1.add(matcher.group(1)+matcher.group(2));
            }
    }



for ( i=0;i<list2.size();i++){
            for (int j=0;j<list1.size();j++){
             if (list2.get(i).equals(list1.get(j))){
                 map.put(list2.get(i),null);
                break;
             }
            }
if (map.get(list2.get(i))==null){
    System.out.print("");
}
else {
    System.out.println("学号和姓名分别为 " + map.get(list2.get(i)) + " 没交作业");
    try {
       writer.write(new String(map.get(list2.get(i))).getBytes());
       writer.write(new String("\r\n").getBytes());
    } catch (IOException e) {
        e.printStackTrace();
    }
    map.remove(list2.get(i));
}
}

        System.out.println("交了"+map.size()+"个人的作业");

    }
}
